package com.zzptc.myk.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class ReadActivity extends AppCompatActivity {
    TextView readtxt;
    String bookname="";
    String finlepath="/sdcard/Download/";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_read);
        initView();
    }

    private void initView() {
        readtxt=findViewById(R.id.readtxt);
        Intent it=getIntent();
        bookname=it.getStringExtra("bookname");
        String content=readAssetsTxt();
        readtxt.setText(content);
    }

    private String readAssetsTxt() {
        try {
           // InputStream is=getAssets().open(bookname+".txt");
            File file =new File(finlepath+bookname+".txt");
            FileInputStream is = new FileInputStream(file);
            int size=is.available();
            byte[] buffer=new byte[size];
            is.read(buffer);
            is.close();
            String text=new String(buffer,"utf-8");
            return text;

        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
